package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.LeaseTermService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.LeaseTerm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "房屋租期管理")
@RestController
@RequestMapping("admin/term")
public class LeaseTermController {

    @Autowired
    private LeaseTermService leaseTermService;

    @GetMapping("list")
    @Operation(summary = "查询所有房屋租期信息")
    public Result<List<LeaseTerm>> list() {
        return Result.ok(leaseTermService.list());
    }

    @PostMapping("saveOrUpdate")
    @Operation(summary = "新增或更新租期信息")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        return Result.ok(leaseTermService.saveOrUpdate(leaseTerm));
    }

    @DeleteMapping("deleteById")
    @Operation(summary = "根据Id删除租期信息")
    public Result deleteById(
            @Parameter(description = "主键",in = ParameterIn.QUERY,required = true)
            @RequestParam("id") Integer id) {
        return Result.ok(leaseTermService.removeById(id));
    }
}
